package sf.config;

import db.domain.User;
import jakarta.annotation.PostConstruct;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sf.database.meta.MetaHolder;
import sf.database.meta.TableMapping;
import sf.database.template.mybatis.MybatisTemplate;

import java.util.Map;

@Service
public class MybatisConfig implements InitializingBean {

    @Autowired
    private SqlSessionFactory sqlSessionFactory;


    public void afterPropertiesSet() throws Exception {
        Configuration configuration = sqlSessionFactory.getConfiguration();
//        for (Map.Entry<Class<?>, TableMapping> entry : MetaHolder.getAllClass().entrySet()) {
//            MybatisTemplate.addResultMap(configuration, entry.getKey(), null);
//        }
        MybatisTemplate.addResultMap(configuration, User.class, null);
        System.out.println(1);
    }

}
